﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Text;

public partial class BaseData_SelectCoupon : System.Web.UI.Page, ICallbackEventHandler
{
    string result = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetOptionsString();
        }
    }

    private void SetOptionsString()
    {
        DataSet dstCoupons = new BLL.CZKZCD().GetUsableCoupon(DateTime.Now);
        ListItem item;
        for (int i = 0; i < dstCoupons.Tables[0].Rows.Count; i++)
        {
            item = new ListItem();
            item.Text = dstCoupons.Tables[0].Rows[i]["DJBH"].ToString() + " 面值：" + string.Format("{0:0.00}", dstCoupons.Tables[0].Rows[i]["XFJE"]) + "元  礼券期限至：" + Convert.ToDateTime(dstCoupons.Tables[0].Rows[i]["YXRQ_E"]).ToShortDateString();
            item.Value = dstCoupons.Tables[0].Rows[i]["DJBH"].ToString();
            dropCoupon.Items.Add(item);
        }
        
        dropCoupon.Items.Insert(0, "");
    }

    public void RaiseCallbackEvent(string eventArgument)
    {
        DataSet dstCoupon = new BLL.CZKZCDMX().GetUsableCoupon(DateTime.Now, eventArgument);
        StringBuilder sb = new StringBuilder();
        sb.Append("<table class='tb' border='0' cellspacing='1' cellpadding='0'><tr class='z1'><td class='zt3'></td><td class='zt3'>礼券号</td>");
        sb.Append("<td class='zt3' style='width: 100px;'>礼券面值</td></tr>");
        for (int i = 0; i < dstCoupon.Tables[0].Rows.Count; i++)
        {
            sb.Append("<tr class='z2'><td class='zt4'><input name='checkbox' type='checkbox' value='" + dstCoupon.Tables[0].Rows[i]["CZKBH"].ToString() + "|" + dstCoupon.Tables[0].Rows[i]["XFJE"].ToString() + "' /></td>");
            sb.Append("<td class='zt4'>" + dstCoupon.Tables[0].Rows[i]["CZKBH"].ToString() + "</td>");
            sb.Append("<td class='zt4'>" + String.Format("{0:0.00}", dstCoupon.Tables[0].Rows[i]["XFJE"]) + "</td></tr>");
        }
        sb.Append("</table>");
        result = sb.ToString();
    }
    public string GetCallbackResult()
    {
        return result;
    }
}
